﻿Imports System.Data.OleDb
Public Class SuatChieuDAO
    Public Function GetTable(ByVal t As String) As DataTable
        Dim dt As DataTable = New DataTable()
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = t
        Dim da As OleDbDataAdapter = New OleDbDataAdapter(str, cn)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function

    Public Function Insert(ByVal tmp As SuatChieuDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "insert into SUATCHIEU (MaCaChieu, GioBatDau, GioKetThuc, NgayChieu, TenPhim, MaPhongChieu, GiaVe) values (@MaCaChieu, @GioBatDau, @GioKetThuc, @NgayChieu, @TenPhim, @MaPhongChieu, @GiaVe)"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2, para3, para4, para5, para6, para7 As OleDbParameter
        para1 = New OleDbParameter("@MaCaChieu", tmp.MaCaChieu)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@GioBatDau", tmp.GioBatDau)
        cmd.Parameters.Add(para2)
        para3 = New OleDbParameter("@GioKetThuc", tmp.GioKetThuc)
        cmd.Parameters.Add(para3)
        para4 = New OleDbParameter("@NgayChieu", tmp.NgayChieu)
        cmd.Parameters.Add(para4)
        para5 = New OleDbParameter("@TenPhim", tmp.TenPhim)
        cmd.Parameters.Add(para5)
        para6 = New OleDbParameter("@MaPhongChieu", tmp.MaPhongChieu)
        cmd.Parameters.Add(para6)
        para7 = New OleDbParameter("@GiaVe", tmp.GiaVe)
        cmd.Parameters.Add(para7)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Update(ByVal tmp As SuatChieuDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "update SUATCHIEU set MaCaChieu=@MaCaChieu,GioBatDau=@GioBatDau,GioKetThuc=@GioKetThuc,NgayChieu=@NgayChieu,TenPhim=@TenPhim,MaPhongChieu=@MaPhongChieu,GiaVe=@GiaVe where MaSuatChieu=@MaSuatChieu"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2, para3, para4, para5, para6, para7, para8 As OleDbParameter
        para1 = New OleDbParameter("@MaCaChieu", tmp.MaCaChieu)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@GioBatDau", tmp.GioBatDau)
        cmd.Parameters.Add(para2)
        para3 = New OleDbParameter("@GioKetThuc", tmp.GioKetThuc)
        cmd.Parameters.Add(para3)
        para4 = New OleDbParameter("@NgayChieu", tmp.NgayChieu)
        cmd.Parameters.Add(para4)
        para5 = New OleDbParameter("@TenPhim", tmp.TenPhim)
        cmd.Parameters.Add(para5)
        para6 = New OleDbParameter("@MaPhongChieu", tmp.MaPhongChieu)
        cmd.Parameters.Add(para6)
        para7 = New OleDbParameter("@GiaVe", tmp.GiaVe)
        cmd.Parameters.Add(para7)
        para8 = New OleDbParameter("@MaSuatChieu", tmp.MaSuatChieu)
        cmd.Parameters.Add(para8)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Delete(ByVal tmp As SuatChieuDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "delete from SUATCHIEU where MaSuatChieu=@MaSuatChieu"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1 As OleDbParameter
        para1 = New OleDbParameter("@MaSuatChieu", tmp.MaSuatChieu)
        cmd.Parameters.Add(para1)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function
End Class
